package com.hziee.mail.dao;

import com.hziee.mail.model.GoodsDirectionaryEntity;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Map;

/**
 * @author ZX
 */
public interface GoodDetailRepository extends JpaRepository<GoodsDirectionaryEntity, Integer>, CrudRepository<GoodsDirectionaryEntity, Integer> {


    /**
     * 查询商品信息
     *
     * @param goodId
     * @return
     */
    @Query(nativeQuery = true, value = "SELECT " +
            "gd.goods_id, " +
            "gd.goods_bright, " +
            "gd.goods_img, " +
            "gd.goods_peizhi, " +
            "gd.goods_title, " +
            "gd.goods_name_two, " +
            "gd.goods_value, " +
            "pci.product_class_name, " +
            "si.amount, " +
            "si.price " +
            "FROM " +
            "goods_directionary gd " +
            "JOIN product_class_info pci on pci.product_class_id = gd.goods_id " +
            "JOIN sku_info si on si.product_class_id = gd.goods_id " +
            "WHERE gd.goods_id = :goodId")
    List<Map> findAllByGoodsId(@Param("goodId") String goodId);
}
